#include<sys/types.h>
#include<signal.h>
#include<stdio.h>
#include <sys/wait.h>
#include<unistd.h>

// int kill(pid_t pid, int sig);

int main()
{
    pid_t pid =fork();
    if(pid==0)
    {
        //子进程
        int i = 0;
        for(i=0;i<5;i++)
        {
            printf("in son process\n");
            sleep(1);
        }
    }
    else
    {
        //父进程
         printf("in father process\n");
         sleep(2);
         printf("kill sub process now \n");
         kill(pid,SIGINT);
        int status;
        pid_t child_pid = waitpid(pid, &status, 0);
        if (WIFEXITED(status)) 
        {
            // 子进程正常退出
            int exit_code = WEXITSTATUS(status);
            printf("子进程退出码：%d\n", exit_code);
        } 
        else if (WIFSIGNALED(status)) 
        {
            // 子进程被信号终止
            int signal_number = WTERMSIG(status);
            printf("子进程被信号终止：%d\n", signal_number);
        }
    }
    return 0;
}